<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>send_my_message</title>
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/send_my_message.css">
    <script src="js/jquery-3.1.1.min.js"></script>
</head>
<body>
    <div class="head">
            <span class="title">在线驾考模拟系统</span>
            <ul>
                <li><a href="send_my_message.html">发布留言</a></li>
            </ul>      
        </div>
    
        <div class="nav">
            <ul>
                <li><a href="index.html">首页</a></li>
                <li><a href="order_exercise.html">顺序练题</a></li>
                <li><a href="error_book.html">错题本</a></li>
                <li><a href="mock_exam.html">模拟测试</a></li>
                <li><a href="message.html">留言板</a></li>
            </ul>
        </div>

        <div class="content">
            <ul>
                <li class="content_span">                    
                    <span>我想要留言...</span>                   
                </li>
                <li>
                    标&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;题：
                    <input type="text"  style='font-size:22px' placeholder="&nbsp;&nbsp;请输入您的标题" onfocus="javascript:this.value=''" id="ipt1">
                    <span class="message_notes">*必填</span>
                </li>
                <li>
                    选&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;填：&nbsp;<input type="text"  style='font-size:22px' placeholder="&nbsp;&nbsp;补充说明" onfocus="javascript:this.value=''" id="ipt2">                       
                </li>
                <li class="message_board">
                    留言内容：<input type="text" class="textarea"  style='font-size:22px' placeholder="&nbsp;&nbsp;请输入您的留言" onfocus="javascript:this.value=''" id="ipt3">
                    <span class="message_notes">*必填</span>
                </li>
            </ul>
            <div class="message_btn">
                <button class="message_btn_con" id="btn1" onclick="sendMessage()">发送留言</button>
            </div>
        </div>
        <script>
            var ipt1 = $('#ipt1')
            var ipt2 = $('#ipt2')
            var ipt3 = $('#ipt3')
            var msgArr = []
            var user_id = localStorage.getItem('user_id')
            
        function sendMessage(){ 
            getMsgList()
            if(!document.getElementById('ipt1').value.length){    
                alert('标题不能为空！');
                document.getElementById('ipt1').focus();
                return false;
            }
            
            if(!document.getElementById('ipt3').value.length){    
                alert('留言不能为空！');
                document.getElementById('ipt3').focus();
                return false;
            }
            var data = {
                // user_id: user_id,
                // bbs_id: ipt2.val(),
                title: ipt1.val(),
                content: ipt3.val()

            }
            // $.ajax({
            //     url: "/api/bbs/InsertOrUpdateBbs",           
			// 	dataType: "json",
			// 	async: "true",
			// 	method: "POST",
			// 	data:data,
			// 	success:function(data) {
            //         alert('发送成功')
            //         ipt1.val('') 
            //         ipt2.val('')    
            //         ipt3.val('')                      
            //     },               
            //     error:function(e){
            //         console.log(e)
            //     }
            // })
            msgArr.data.push(data)
            localStorage.setItem('msgList', JSON.stringify(msgArr))
            alert('发送成功')
        }
        function getMsgList() {
            if(localStorage.getItem('msgList')) {
                msgArr = JSON.parse(localStorage.getItem('msgList')) 
            } else {
                msgArr = {
                    data: []
                }
            }
        }
        </script>
</body>
</html>